﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace Medianamik.Core.Sugar
{
    public static class Types
    {
        public static bool ValidateDataType(string pDataTypeName, string pValue)
        {
            bool result = false;

            switch (pDataTypeName)
            {
                case "varchar" :
                    result = true;
                    break;
                case "int":
                    int test;
                    result = int.TryParse(pValue, out test);
                    break;
                default:
                    throw new Exception("Medianamik does not support DataType : " + pDataTypeName);
            }

            return result;
        }

        /// <summary>
        /// Determines whether the specified obj type is nullable.
        /// </summary>
        /// <param name="objType">Type of the obj.</param>
        /// <returns>
        /// 	<c>true</c> if the specified obj type is nullable; otherwise, <c>false</c>.
        /// </returns>
        public static bool IsNullable(Type objType)
        {
            if (!objType.IsGenericType)
                return false;

            return objType.GetGenericTypeDefinition().Equals(typeof(Nullable<>));
        }
    }
}
